#include "loop_queue.h"

LoopQueue::LoopQueue(int s) : size(s) { data = new int[s]; }

LoopQueue::~LoopQueue() { delete data; }

int LoopQueue::push(int val) {
  if (count == size) {
    data[write] = val;
    write = (write + 1) % size;
    read = write;
    return -1;
  } else {
    data[write] = val;
    write = (write + 1) % size;
    count++;
    return 0;
  }
  return 0;
}

int LoopQueue::pop() {
  if (count == 0) {
    return -1;
  } else {
    int ret = data[read];
    read = (read + 1) % size;
    count--;
    return ret;
  }
  return -1;
}